package org.example.ttms.controller;

import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.text.Text;
import org.example.ttms.customize.AddTicket;
import org.example.ttms.customize.Detail;
import org.example.ttms.customize.Window;
import org.example.ttms.entityClass.train.Route;

public class RouteDetailController {

    @FXML
    private Text idText;

    @FXML
    private Text startStationText;

    @FXML
    private Text stationNumText;

    @FXML
    private Text endStationText;

    @FXML
    private Text tripsNumText;

    @FXML
    private Label label;

    @FXML
    private TableView<String> routeTableView;

    @FXML
    private TableColumn<String, String> routeTableColumn;

    @FXML
    private TableView<String> tripsTableView;

    @FXML
    private TableColumn<String, String> tripsTableColumn;

    public void initialize(){
        Route route = Detail.route;
        idText.setText(String.valueOf(route.getRouteId()));
        startStationText.setText(route.getStartStation());
        endStationText.setText(route.getEndStation());
        stationNumText.setText(String.valueOf(route.getStationNum()));
        tripsNumText.setText(String.valueOf(route.getTripsNum()));
        ObservableList<String> stationObservableList = FXCollections.observableList(route.getStationList());
        routeTableColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue()));
        routeTableView.setItems(stationObservableList);
        ObservableList<String> tripsObservableList = FXCollections.observableList(route.getTripsList());
        tripsTableColumn.setCellValueFactory(param -> new SimpleStringProperty(param.getValue()));
        tripsTableView.setItems(tripsObservableList);
        label.setVisible(tripsObservableList.isEmpty());
    }
}

